package com.sailfish.springbootdemo.dao.db7;

import com.sailfish.springbootdemo.common.DB7TableName;
import com.sailfish.springbootdemo.pojo.db7.TbBoardNodeToKnowledgeNode;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface TbBoardNodeToKnowledgeNodeDao {

    @Select("<script> " +
            "SELECT * FROM " + DB7TableName.TB_BOARD_NODE_TO_KNOWLEDGE_NODE +
            " WHERE 1=1 " +
            "<if test='board_node_name != null and board_node_name != \"\"'>" +
            " AND board_node_name = #{board_node_name} " +
            "</if>" +
            "</script>")
    List<TbBoardNodeToKnowledgeNode> getByBoardNodeName(@Param("board_node_name") String board_node_name);

    @Insert("INSERT INTO " + DB7TableName.TB_BOARD_NODE_TO_KNOWLEDGE_NODE + " " +
            "(board_node_name, board_node_id, knowledge_node_name, create_time, update_time) " +
            "VALUES " +
            "(#{board_node_name}, #{board_node_id}, #{knowledge_node_name}, #{create_time}, #{update_time})")
    @Options(useGeneratedKeys = true, keyProperty = "tb_board_node_to_knowledge_node_id")
    int insert(TbBoardNodeToKnowledgeNode record);

    @Update("<script> " +
            "UPDATE " + DB7TableName.TB_BOARD_NODE_TO_KNOWLEDGE_NODE + " SET " +
            "board_node_name = #{board_node_name}, " +
            "board_node_id = #{board_node_id}, " +
            "knowledge_node_name = #{knowledge_node_name}, " +
            "update_time = #{update_time} " +
            "WHERE tb_board_node_to_knowledge_node_id = #{tb_board_node_to_knowledge_node_id}" +
            "</script>")
    int update(TbBoardNodeToKnowledgeNode record);

    @Delete("DELETE FROM " + DB7TableName.TB_BOARD_NODE_TO_KNOWLEDGE_NODE +
            " WHERE tb_board_node_to_knowledge_node_id = #{id}")
    int deleteById(@Param("id") Integer id);
}
